

// pages/account/personalinfo.js


import * as echarts from '../../ec-canvas/echarts';

const app = getApp();

function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);

  var option = {
    backgroundColor: "#ffffff",
    color: ["#37A2DA"],
    tooltip: {},
    xAxis: {
      show: false
    },
    yAxis: {
      show: false
    },
    radar: {
      // shape: 'circle',
      indicator: [{
        name: '拥有房屋数量',
        max: 5
      },
      {
        name: '目标金额',
        max: 5000000
      },
      {
        name: '预约次数',
        max: 3
      },
      {
        name: '购房次数',
        max: 5
      },
      {
        name: '年收入',
        max: 500000
      },
      {
        name: '想要户型',
        max: 500
      }
      ]
    },
    series: [{
      name: '客户数据',
      type: 'radar',
      data: [{
        value: [4, 5000000, 2, 4, 470000, 490],
        name: '客户'
      }
      ]
    }]
  };

  chart.setOption(option);
  return chart;
}
var dateTimePicker = require('../../utils/dateTimePicker.js');
var util = require('../../utils/util.js');
import WxValidate from '../../utils/validate';
var inputContent = {};//输入内容
Page({
  onShareAppMessage: function (res) {
    return {
      title: 'ECharts 可以在微信小程序中使用啦！',
      path: '/pages/index/index',
      success: function () { },
      fail: function () { }
    }
  },
  data: {
    ec: {
      onInit: initChart
    },
    time: '12:00',
    dateTimeArray: null,
    dateTime: null,
    dateTimeArray1: null,
    dateTime1: null,
    startYear: 2000,
    endYear: 2050,
    isLogin: util.isLogin(),
    date: new Date().Format("yyyy-MM-dd"),
    entranceDate: new Date().Format("yyyy"),
    credentialsIndex: 0,
    nation: ["预约中", "已预约"],//预约状态
    nationIndex:0,
    orderInfo: null
  },
  onLoad: function (options) {
    var aa=this;
    console.log(app.globalData.orderInfo[options.idx]);
    this.setData({
      orderInfo: app.globalData.orderInfo[options.idx]
    })
    console.log(this.data.orderInfo.appointmentEC.ldate);

    if (this.data.orderInfo.dictionary.dictdataValue=="预约中"){
      aa.data.nationIndex=0;
    }
    console.log(this.data.orderInfo);
    // 页面初始化 options为页面跳转所带来的参数
    // 获取完整的年月日 时分秒，以及默认显示的数组
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    // 精确到分的处理，将数组的秒去掉
    var lastArray = obj1.dateTimeArray.pop();
    var lastTime = obj1.dateTime.pop();
    this.setData({
      dateTime: obj.dateTime,
      dateTimeArray: obj.dateTimeArray,
      dateTimeArray1: obj1.dateTimeArray,
      dateTime1: obj1.dateTime
    });
  },
  changeTime(e) {
    this.setData({ time: e.detail.value });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    this.setData({
      isLogin: util.isLogin(),
      userData: wx.getStorageSync("userData") || ""//用户信息
    })
   

  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  wxValidate: function () {
    //验证表单
    this.WxValidate = new WxValidate({
      IDCard: { //验证规则 input name值
        required: true,
        idcard: true
      },
      Name: {
        required: true,
        minlength: 2
      },
      TelNum: {
        required: true,
        tel: true
      },
      QQNumber: {
        required: true,
        digits: true,
        minlength: 5
      },
      University: {
        required: true,
        minlength: 4
      },
      Colledge: {
        required: true
      },
      MajorCode: {
        required: true
      },
      ClassCode: {
        required: true
      },
    })

  },
  //时间类型选择
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
    inputContent[e.currentTarget.id] = this.data.date.replace(/-/g, "");
  },
  //获取用户输入
  bindChange: function (e) {
    inputContent[e.currentTarget.id] = e.detail.value
    console.log(inputContent);
  },
  /**
   * 个人信息提交数据
   */
  personalInfoSubmit: function (e) {
    //调用验证表单方法
    const params = e.detail.value
    console.log(params);
    inputContent = util.mergeJsonObject(inputContent, params);
    console.log(inputContent);
    if (!this.WxValidate.checkForm(e)) {
      const error = this.WxValidate.errorList
      wx.showModal({
        title: '友情提示',
        content: error[0].msg,
        showCancel: false,
        confirmColor: "#f26604",
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
          }
        }
      })
      console.log(error)
      return false
    } 
  }
})